#!/usr/bin/env python
# encoding: utf-8

import os
from loguru import logger as real_logger
real_logger.remove()
from pathlib import Path

# 日志格式重新整理，增加线程，进程字段
fmt = "[{time:%y-%m-%d %H:%M:%S}][P:{process:05d}][T:{thread:05d}][{level}][{name}.{function}][{line:04d}]:{message}"

log_path_prefix = Path(__file__).parent.parent.parent.as_posix()
# 设计器本身日志，执行器日志分开, 输出文件暂不区分日志级别
design_log_file_path = 'log/{time:YYYY-MM-DD}/running.log'
run_log_file_path = 'log/{time:YYYY-MM-DD}/running.log'

# 设计器日志/ 设计器日常，通过进程号区分
real_logger.add(
    os.path.join(log_path_prefix, design_log_file_path),
    format=fmt,
    enqueue=True,
    filter=lambda r: 'RunInAnotherProcess' not in r["process"].name,
    rotation='00:00',
    retention="10 days"
)

real_logger.add(
    os.path.join(log_path_prefix, run_log_file_path),
    format=fmt,
    enqueue=True,
    filter=lambda r: 'RunInAnotherProcess' in r["process"].name,
    rotation='00:00',
    retention="10 days"
)
logger = real_logger
